// pages/detail-video/detail-video.js
import {
  getMVUrl,
  getMVInfo,
  getMVRelated
} from '../../../services/video'
Page({
  data: {
    id: 0,
    mvUrl: '',
    mvInfo: {},
    relatedVideo: [],
    danmuList: [{
      text: '第 1s 出现的弹幕',
      color: '#ff0000',
      time: 1
    }, {
      text: '第 3s 出现的弹幕',
      color: '#ff00ff',
      time: 3
    }]
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const id = options.id
    this.setData({
      id
    })
    // 请求数据
    this.fetchMVUrl()
    this.fetchMVInfo()
    this.fetchMVRelated()
  },
  // 相关请求
  async fetchMVUrl() {
    const res = await getMVUrl(this.data.id)
    this.setData({
      mvUrl: res.data.url
    })
  },
  async fetchMVInfo() {
    const res = await getMVInfo(this.data.id)
    this.setData({
      mvInfo: res.data
    })
  },
  async fetchMVRelated() {
    const res = await getMVRelated(this.data.id)
    this.setData({
      relatedVideo: res.data
    })
  }
})